@include('admin.public.head')

<div class="ibox-title">
    <h5>輪播圖添加</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label">方案名稱：</label>
            <div class="col-sm-9">
                <input type="text" name="title" class="form-control"  value="{{$result->title??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">方案内容：</label>
            <div class="col-sm-8">
                <script id="content" name="content" type="text/plain" style="height:300px;">{!! $result->content??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>


        <div class="form-group">
            <label class="col-sm-3 control-label">所需積分：</label>
            <div class="col-sm-9">
                <input type="number" min="0" name="integarl" class="form-control" placeholder="所需積分" value="{{$result->integarl??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">所需金額：</label>
            <div class="col-sm-9">
                <input type="number" min="0" name="money" class="form-control" placeholder="所需金額" value="{{$result->money??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <label class="col-sm-3 control-label">有效时长:</label>
            <div class="col-sm-4 col-sm-offset-3" style="float:left;display:flex;float: none;
vertical-align: middle;" >

                    <input type="number" min="0" name="valid_year" class="form-control" placeholder=":年" value="{{$result->valid_year??'0'}}" style="width: 60px">年&nbsp
                    <input type="number" min="0" name="valid_month" class="form-control" placeholder=":月" value="{{$result->valid_month??'0'}}" style="width: 60px">月&nbsp
                    <input type="number" min="0" name="valid_day" class="form-control" placeholder=":日" value="{{$result->valid_day??'0'}}" style="width: 60px">日&nbsp
                    <input type="number" min="0" name="valid_time" class="form-control" placeholder=":时" value="{{$result->valid_time??'0'}}" style="width: 60px">时&nbsp
                    <input type="number" min="0" name="valid_minute" class="form-control" placeholder=":时" value="{{$result->valid_minute??'0'}}" style="width: 60px">分&nbsp
                    <input type="number" min="0" name="valid_s" class="form-control" placeholder=":分" value="{{$result->valid_s??'0'}}" style="width: 60px">秒&nbsp
            </div>
        </div>

        {{--
        <td>
            {{$v->pay_type->pay_name??''}}:年&nbsp
            {{$v->pay_type->pay_name??''}}:月&nbsp
            {{$v->pay_type->pay_name??''}}:日&nbsp
            {{$v->pay_type->pay_name??''}}:时&nbsp
            {{$v->pay_type->pay_name??''}}:分&nbsp
        </td>--}}

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a href="/integral_plan" class="btn btn-primary" >返回套餐列表</a>
            </div>
        </div>

    </form>
</div>

<script>

    var content = UE.getEditor('content');

    $('.do').click(function(){
        var form = new FormData();

        var id = $('input[name="id"]').val();
        var title = $('input[name="title"]').val();
        var integarl = $('input[name="integarl"]').val();
        var money = $('input[name="money"]').val();

        var valid_year = $('input[name="valid_year"]').val();
        var valid_month = $('input[name="valid_month"]').val();
        var valid_day = $('input[name="valid_day"]').val();
        var valid_time = $('input[name="valid_time"]').val();
        var valid_minute = $('input[name="valid_minute"]').val();
        var valid_s = $('input[name="valid_s"]').val();

        var plan_content = content.getContent();

        form.append("title", title);
        form.append("content", plan_content);
        form.append("integarl", integarl);
        form.append("money", money);

        form.append("valid_year", valid_year);
        form.append("valid_month", valid_month);
        form.append("valid_day", valid_day);
        form.append("valid_time", valid_time);
        form.append("valid_minute", valid_minute);
        form.append("valid_s", valid_s);

        form.append("id", id);

        $.ajax({
            type: 'POST',
            url: '/integral_plan_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });
</script>
